var form = document.getElementsByTagName("form")[0];
var div1 = form.getElementsByClassName("div1")[0];
var code = form.code;
var password = form.password;
var paypassword = form.paypassword;
var nameval = form.name;
var phone = form.phone;
var address = form.address;
var email = form.email;
var repassword = document.getElementById("repassword");
var s1 = document.getElementById("s1");
var s2 = document.getElementById("s2");
var s3 = document.getElementById("s3");
var s4 = document.getElementById("s4");
var s5 = document.getElementById("s5");
var s6 = document.getElementById("s6");
var s7 = document.getElementById("s7");

var sp1 = document.getElementById("sp1");
var submit = document.getElementById("submit");
var input = form.getElementsByTagName("input");
nameval.onblur = function () {
    fn(this);
    fn2(s1,this);
    var name = $(nameval).val();
    $.get("checkUsername.do?username=" + name, function (data) {
        if (!data.data) {
            layer.msg("用户已存在！");
            $("#submit").addClass("layui-btn-disabled");
        } else {
            $("#submit").removeClass("layui-btn-disabled");
        }
    });
};
password.onblur = function () {
    fn(this);
    fn2(s2,this);
};
repassword.onblur = function () {
    fn2(s3,this);
    var str = this.value;
    if(password.value === this.value){
        this.setAttribute("flag",1);
        // this.style.border = "2px solid green";
    }
    else{
        this.setAttribute("flag",0);
        // this.style.border = "2px solid red";
    }

};

function fn(receive) {
    var str = receive.value;
    var reg;
    switch (receive.name) {
        case "username":
            reg = /^[a-zA-Z\w]{4,16}$/;
            break;
        case "code":
            reg = /^[a-zA-Z\d]{4,6}$/;
            break;
        case "password":
            reg = /^\w{6,40}$/;
            break;
    }
}

function fn1(span) {
    span.style.transform = "translate(0,-20px)";
    span.style.fontSize = "10px";
    span.style.color = "#7390fe";
    span.style.padding = "0 2px";
}
nameval.onfocus = function () {
    fn1(s1);
};
password.onfocus = function () {
    fn1(s2);
};
repassword.onfocus = function () {
    fn1(s3);
};
phone.onfocus = function () {
    fn1(s5);
};
phone.onblur = function () {
    fn2(s5,this);
};
address.onfocus = function () {
    fn1(s6);
};
address.onblur = function () {
    fn2(s6,this);
};
email.onfocus = function () {
    fn1(s7);
};
email.onblur = function () {
    fn2(s7,this);
};
function fn2(span,that) {
    if(that.value === ''){
        span.style.transform = "translate(0,0)";
        span.style.fontSize = "16px";
        span.style.color = "#b0b0b0";
    }
}

